// pages/phone/index.js
var app = getApp(),
    core = app.requirejs("core");

Page({
    data: {
        phoneNumber: '',
        available: true,
        config: app.config,
        show_dial: false
    },
 
    onLoad: function (options) {

    },

    onShow: function () {
        if (this.data.available) {
            this.getTabbar();
        }
    },

    // 获取tabbar
    getTabbar: function (){
        var that = this;

        core.get("index/tabbar", {}, function (res) {
            if (res.code == 0) {
                var tabbar = res.info.tabbar.list;
                if (tabbar.length > 0) {
                    for (var i = 0; i < tabbar.length; i++) {
                        if (tabbar[i].url == '/yb_mingpian/pages/phone/index') {
                            that.setData({
                                phoneNumber: tabbar[i].phone ? tabbar[i].phone : ''
                            })

                            that.phoneCall();
                            break;
                        }
                    };
                } else {
                    core.alert('没有获取到信息')
                }
            } else {
                core.alert(res.msg)
            }
        })
    },

    // 打电话
    phoneCall: function () {
        if (this.data.phoneNumber) {
            wx.makePhoneCall({
                phoneNumber: this.data.phoneNumber
            })
        } else {
            core.alert('没有获取到电话')
        }
    },

    onHide: function () {
        this.setData({
            available: false,
            show_dial: true
        })
    },
})